# Maintainer: Adrian Pop <adrian.pop@liu.se>

_realname=uasm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.50.r623.8d1afb0
pkgrel=1
_commit='8d1afb0a040217f87106b0c6b924bf9eb0254a2b'
pkgdesc="UASM is a free MASM-compatible assembler based on JWasm"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('Watcom-1.0')
url="https://github.com/Terraspace/UASM"
depends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip')
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-gcc")
source=("UASM"::"git+https://github.com/Terraspace/UASM.git#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/UASM"
  local _ver=$(sed -ne '/#define\s*_UASM_VERSION_STR_\s*"/ { s/^.*"\(.*\)"\s*$/\1/; p; q }' H/globals.h)
  printf "%s.r%s.%s" ${_ver} "$(git rev-list --count $_commit)" "$(git rev-parse --short $_commit)"
}

prepare() {
  cd ${srcdir}/UASM/
  rm -rf MinGWR
  sed -i -e 's/^extra_c_flags = .*$/& -fcommon/' GccWin.mak
}

build() {
  cd ${srcdir}/UASM/
  make -f GccWin.mak
}

package() {
  install -Dm744 ${srcdir}/UASM/MinGWR/hjwasm.exe "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 ${srcdir}/UASM/License.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
